﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;

namespace ASoft.Led
{
    public abstract class LedPicBase
    {
        public LedPicBase(LedCfg ledCfg, string ledPath)
        {
            this.LedCfg = ledCfg;
            this.LedPath = ledPath;
        }

        public string LedPath { get; private set; }

        public LedCfg LedCfg { get; private set; }

        public string TemplatePicPath { get { return Path.Combine(LedPath, GetTemplatePicName()); } }

        protected abstract string GetTemplatePicName();

        public string SendPicPath { get { return Path.Combine(LedPath, GetSendPicName()); } }

        protected abstract string GetSendPicName();

        protected void CreatePic(string templatePath, string createPath, List<DrawItem> items)
        {
            if (items == null)
            {
                items = new List<DrawItem>();
            }
            Bitmap bmp = new Bitmap(templatePath);
            Graphics graphics = Graphics.FromImage(bmp);
            Font font = new Font("宋体", 11);
            Brush brush = new SolidBrush(Color.Red);
            StringFormat stringFormat = new StringFormat();
            stringFormat.Alignment = StringAlignment.Center;
            items.ForEach(p =>
            {
                graphics.DrawString(p.Text, font, brush, p.X, p.Y, stringFormat);
            });
            bmp.Save(createPath, System.Drawing.Imaging.ImageFormat.Bmp);
            graphics.Dispose();
            bmp.Dispose();
        }

        protected void CreatePic(List<DrawItem> items)
        {
            CreatePic(TemplatePicPath, SendPicPath, items);
        }

        public abstract void Create(params object[] ps);

    }
}
